home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / rexx / answerfax.avm < prev    next >
Text File  |  1995-03-09  |  10KB  |  408 lines

  1. /* TITLE: avm:rexx/answerfax.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername faxscript datascript distinctivering 'CID$' acidname '$' acidnumber '$'
  23. call setclip(address() || 'FAXSCRIPT', faxscript)
  24. call setclip(address() || 'DATASCRIPT', datascript)
  25. call setclip(address() || 'CIDNAME', acidname)
  26. call setclip(address() || 'CIDNUMBER', acidnumber)
  27.  
  28. startup:
  29. mailbox = 'anonymous'
  30. signal stdfax
  31. exit
  32.  
  33. /* TITLE: avm:rexx/simplestdtail.avm */
  34. /* This is the standard tail */
  35. exit
  36.  
  37. exit
  38.  
  39. mailboxDir: procedure
  40.     parse arg mailbox
  41.  
  42.     return 'avm:' || mailbox || '/'
  43.  
  44. logFile: procedure
  45.     parse arg mailbox, magiccookie
  46.  
  47.     return 'avm:' || mailbox || '/logs/' || magiccookie
  48.  
  49. voiceFile: procedure
  50.     parse arg mailbox, magiccookie
  51.  
  52.         if (verify(magiccookie, '/:', 'M') = 0) then
  53.           return 'avm:' || mailbox || '/voices/' || magiccookie
  54.         else
  55.           return magiccookie
  56.  
  57. makeUniqueFile: procedure
  58.     if arg() ~= 0 then do
  59.         rc = "makeUniqueFile: bad args"
  60.         signal error
  61.     end
  62.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  63.  
  64. convertToDate: procedure
  65.     if arg() ~= 1 then do
  66.         rc = "convertToDate: bad args"
  67.         signal error
  68.     end
  69.     parse arg timeInC
  70.  
  71.     actualTime = (timeInC - (2922)*86400) // (86400)
  72.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  73.  
  74.     return actualDate /* returning it in 'internal' format */
  75.  
  76. convertToTime: procedure
  77.     if arg() ~= 1 then do
  78.         rc = "convertToTime: bad args"
  79.         signal error
  80.     end
  81.     parse arg timeInC
  82.     
  83.     actualTime = (timeInC - (2922)*86400) // (86400)
  84.  
  85.     return actualTime
  86.  
  87. cTime: procedure
  88.     /* 2922 = 8*365 + 2 */
  89.     /* 86400 = 24*60*60 */
  90.     return (date('i')+2922)*86400 + time('s')
  91.  
  92. /* this returns a handle that you must use after initializing log. */
  93. initLogEntry: procedure expose log.
  94.     if arg() ~= 0 then do
  95.         rc = "initLogEntry: bad args"
  96.         signal error
  97.     end
  98.     
  99.     drop log.
  100.         log. = ''
  101.  
  102.         acidname = getclip(address() || 'CIDNAME')
  103.         acidnumber = getclip(address() || 'CIDNUMBER')
  104.  
  105.     /* 2922 = 8*365 + 2 */
  106.     /* 86400 = 24*60*60 */
  107.     log.time = (date('i')+2922)*86400 + time('s')
  108.     log.cidname = acidname
  109.     log.cidnumber = acidnumber
  110.  
  111.     return
  112.  
  113. loadLogEntry: procedure expose log.
  114.     if arg() ~= 2 then do
  115.         rc = "loadLogEntry: bad args"
  116.         signal error
  117.     end
  118.     parse arg mailbox, handle
  119.  
  120.         drop log.
  121.         log. = ''
  122.  
  123.     if ~exists(mailboxDir(mailbox)) then do
  124.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  125.         return
  126.     end
  127.  
  128.     opened = open(handle, logFile(mailbox, handle), 'r')
  129.         if opened then do
  130.         call showDebugger('Loading entry' logFile(mailbox, handle))
  131.         do while ~eof(handle)
  132.             line = readln(handle)
  133.             parse upper var line variable '=' value
  134.             log.variable = value
  135.         end
  136.         call close(handle)
  137.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  138.     return
  139.  
  140. /* pass a handle here */
  141. saveLogEntry: procedure expose log.
  142.     if arg() ~= 2 then do
  143.         rc = "saveLogEntry: bad args"
  144.         signal error
  145.     end
  146.     parse arg mailbox, handle
  147.  
  148.     if ~exists(mailboxDir(mailbox)) then do
  149.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  150.         return
  151.     end
  152.  
  153.     opened = open(handle, logFile(mailbox, handle), 'w')
  154.  
  155.     if opened then do
  156.         call showDebugger('Saving entry' logFile(mailbox, handle))
  157.         call writeln(handle, 'TYPE=' || log.type)
  158.         call writeln(handle, 'TIME=' || log.time)
  159.         call writeln(handle, 'LENGTH=' || log.length)
  160.  
  161.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  162.  
  163.         call writeln(handle, 'CIDNAME=' || log.cidname)
  164.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  165.  
  166.         call writeln(handle, 'COMMENT=' || log.comment)
  167.  
  168.         call writeln(handle, 'FILENAME=' || log.filename)
  169.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  170.  
  171.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  172.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  173.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  174.  
  175.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  176.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  177.  
  178.         call close(handle)
  179.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  180.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  181.  
  182.     return
  183.  
  184. /* pass a handle here */
  185. updateLogEntry: procedure expose log.
  186.     if arg() ~= 2 then do
  187.         rc = "updateLogEntry: bad args"
  188.         signal error
  189.     end
  190.     parse arg mailbox, handle
  191.  
  192.     if ~exists(mailboxDir(mailbox)) then do
  193.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  194.         return
  195.     end
  196.  
  197.     if ~exists(logFile(mailbox, handle)) then do
  198.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  199.         return
  200.     end
  201.     opened = open(handle, logFile(mailbox, handle), 'w')
  202.  
  203.     if opened then do
  204.         call showDebugger('Updating entry' logFile(mailbox, handle))
  205.         call writeln(handle, 'TYPE=' || log.type)
  206.         call writeln(handle, 'TIME=' || log.time)
  207.         call writeln(handle, 'LENGTH=' || log.length)
  208.  
  209.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  210.  
  211.         call writeln(handle, 'CIDNAME=' || log.cidname)
  212.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  213.  
  214.         call writeln(handle, 'COMMENT=' || log.comment)
  215.  
  216.         call writeln(handle, 'FILENAME=' || log.filename)
  217.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  218.  
  219.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  220.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  221.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  222.  
  223.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  224.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  225.  
  226.         call close(handle)
  227.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  228.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  229.  
  230.     return
  231.  
  232.  
  233.  
  234. showDebugger: procedure
  235.     if arg() ~= 1 then do
  236.         say "showDebugger: ERROR"
  237.         exit 20
  238.     end
  239.  
  240.     parse arg debuggerInfo
  241.     
  242.     firstLine = sourceline(1)
  243.     parse var firstLine '/*' 'TITLE:' title '*/'
  244.     if showlist('p', 'AVMLOGGER') then
  245.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  246.     else
  247.         say title ':' debuggerInfo
  248.  
  249.     return 
  250.  
  251. /*-----------------------------------------------------------------------*/
  252. /*                         signal processing                             */
  253.  
  254. arexxerror:
  255. error:
  256.     call showDebugger("Error" rc "at line" sigl)
  257.     exit 20
  258.  
  259. break_c:
  260. halt:
  261.     call showDebugger("Halt/Break_C at line" sigl)
  262.     exit 20
  263.  
  264. novalue:
  265.     call showDebugger("No value at line" sigl)
  266.     exit 20
  267.  
  268. syntax:
  269.     call showDebugger("Syntax error" rc "at line" sigl)
  270.     exit 20
  271.  
  272. exit
  273.  
  274. /* this requires logfunctions.avm */
  275.  
  276. loadMailbox: procedure expose mailbox.
  277.     if arg() ~= 1 then do
  278.         rc = "loadMailbox: bad args"
  279.         signal error
  280.     end
  281.  
  282.         mailbox. = ''
  283.     parse arg mailbox
  284.  
  285.     handle = 'mailboxconfig'
  286.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  287.     if opened then do
  288.         do while ~eof(handle)
  289.             line = readln(handle)
  290.             parse upper var line variable '=' value
  291.             mailbox.variable = value
  292.         end
  293.         call close(handle)
  294.     end
  295.     return
  296.  
  297. /* pass a handle here */
  298. saveMailbox: procedure expose mailbox.
  299.     if arg() ~= 1 then do
  300.         rc = "saveMailbox: bad args"
  301.         signal error
  302.     end
  303.     parse arg mailbox
  304.  
  305.     handle = 'mailboxconfig'
  306.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  307.  
  308.     if opened then do
  309.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  310.  
  311.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  312.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  313.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  314.  
  315.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  316.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  317.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  318.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  319.  
  320.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  321.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  322.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  323.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  324.  
  325.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  326.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  327.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  328.  
  329.         call close(handle)
  330.     end
  331.  
  332.     return
  333.  
  334. stdabort:
  335. exit
  336.  
  337. stdbusy:
  338. exit
  339.  
  340. stderror:
  341. exit
  342.  
  343. stdtimedout:
  344. exit
  345.  
  346. stdfaxinstruct:
  347. 'playvoice' 'avm:voices/FaxStarting'
  348. action = rc
  349. select
  350.   when action = 0 then nop
  351.   when action = 1 then do; call checkifabort; end
  352.   when action = 4 then nop
  353.   when action = 5 then nop
  354.   when action = 8 then signal stdbusy
  355.   when action = 12 then signal stdabort
  356.   when action = 14 then nop
  357.   when action = 16 then nop
  358.   otherwise signal arexxerror
  359. end
  360.  
  361. stdfax:
  362. faxscript = getclip(address() || 'FAXSCRIPT')
  363. if faxscript = '' then faxscript = 'handlefax'
  364. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  365. else address rexx faxscript address() 'anonymous'
  366. exit
  367.  
  368. stddatainstruct:
  369. 'playvoice' 'avm:voices/DataStarting'
  370. action = rc
  371. select
  372.   when action = 0 then nop
  373.   when action = 1 then do; call checkifabort; end
  374.   when action = 4 then nop
  375.   when action = 5 then nop
  376.   when action = 8 then signal stdbusy
  377.   when action = 12 then signal stdabort
  378.   when action = 14 then nop
  379.   when action = 16 then nop
  380.   otherwise signal arexxerror
  381. end
  382.  
  383. stddata:
  384. datascript = getclip(address() || 'DATASCRIPT')
  385. if datascript = '' then datascript = 'handledata'
  386. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  387. else address rexx datascript address()
  388. exit
  389.  
  390. checkifabort:
  391. 'readnkeys' '1' '3'
  392. action = rc
  393. if action = 0 then value = result
  394. select
  395.   when action = 0 then do; if value = '*' then signal stdabort; end
  396.   when action = 4 then nop
  397.   when action = 5 then nop
  398.   when action = 8 then signal stdbusy
  399.   when action = 10 then nop
  400.   when action = 12 then signal stdabort
  401.   when action = 14 then signal stderror
  402.   when action = 16 then signal stderror
  403.   otherwise signal arexxerror
  404. end
  405. return
  406.  
  407.  
  408.